core.JSApplication = function(){};

core.startApplication = function(aCode, aClass, aName, aDescription){
    if(core.jsApplications[aCode]){
        core.log('Application already started');
        return core.jsApplications[aCode];
    }
//    js.loadStyleSheet(aCode);
    var instance = null;
//    core.log('Loading module '+aCode);
    js.loadModule(aCode, function(){
        var constructor = core.findElementByItsName(aClass);
        if(constructor){
            instance = new constructor();
//            core.log('Adding new application now...'+aCode);
            core.jsApplications[aCode] = instance;
            instance.init({
                code: aCode,
                description: aDescription,
                name: aName
            });
        }else{
            core.log('Can\'t find constructor '+aClass);
        }
    }, false);
    return instance;
};

core.jsApplications = {};
core.jsDialogs = {};

core.extendClass('core.JSApplication', 'core.Class');

core.JSApplication.prototype.init = function(config){
    this['core.Class_init'](config);
//    this.superCall('init', arguments, config);
    this.jsAppCode = config.code;
    this.jsAppDescription = config.description;
    this.jsAppName = config.name;
    this.frames = [];
    this.workspaces = {};
};

core.JSApplication.prototype.getFrame = function(aFrameName){
    for (var id in this.frames) {
        var frame = this.frames[id];
        if(frame && frame.code==(this.jsAppCode+'-'+aFrameName) && !frame.dynamic)
            return frame;
    }
    return null;
}

core.JSApplication.prototype.getFrameElement = function(aFrameName){
    var frame = this.getFrame(aFrameName);
    if(frame)
        return frame.frame;
    return null;
}

core.JSApplication.prototype.loadDockIndicator = function(aWorkspace){
    
};

core.createDialog = function(aText, aTitle, aMaxWidth, aOkHandler){
    var lbl = new core.Label({
        align: 'left',
        text: aText
    });
    var okButton = new core.form.Button({
        text: 'Close',
        align: 'center',
        handler: function(){
            if(aOkHandler)
                aOkHandler();
        }
    });
    var dlg = new core.Dialog({
       title: aTitle,
       items: [lbl, okButton],
       rows: '1, d',
       columns: '1',
       maxWidth: aMaxWidth || 500
    });
    dlg.closeButton = okButton;
    return dlg;
}

core.JSApplication.prototype.showDefaultError = function(code, text){
    this.showError(text);
}

core.JSApplication.prototype.showError = function(aError, aTitle, aOkHandler){
    var dlg = core.createDialog(aError, aTitle || (this.jsAppName+': error'),
            500, function(){
                core.desktop.closeDialog(dlg);
                if(aOkHandler)
                    aOkHandler();
            });
    core.desktop.showDialog(dlg);
    dlg.closeButton.doFocus();
    return dlg;
}

core.JSApplication.prototype.send = function(aConfig){
    core.net.sendMessage({
        app: this.jsAppCode,
        application: this,
        method: aConfig.method,
        message: aConfig.message,
        disableMe: aConfig.disable,
        okHandler: aConfig.ok,
        errorHandler: aConfig.error,
        fullDisable: true
    });
}

core.JSApplication.prototype.sendMessage = function(aMethod, aMessage, aOkHandler, aErrorHandler, aDisableMe){
    core.net.sendMessage({
        app: this.jsAppCode,
        method: aMethod,
        message: aMessage,
        disableMe: aDisableMe,
        okHandler: aOkHandler,
        errorHandler: aErrorHandler
    });
};

core.JSDialog = function(){};

core.extendClass('core.JSDialog', 'core.Class');

core.JSDialog.prototype.init = function(config){
    this['core.Class_init'](config);
    this.application = config.application;
    this.id = config.id;
    this.dialog = this.createDialog(config.data || {});
    core.desktop.showDialog(this.dialog);
    if(this.dialog.defaultItem)
        this.dialog.defaultItem.doFocus();
};

core.JSDialog.prototype.createDialog = function(aData){
    return new core.Dialog({
        title: aData.title || 'Untitled dialog'
    });
};

core.JSDialog.prototype.send = function(aConfig){
    core.net.sendMessage({
        dialog: this.id,
        application: this.application,
        method: aConfig.method,
        message: aConfig.message,
        disableMe: aConfig.disable || aConfig.disableItem,
        okHandler: aConfig.ok,
        errorHandler: aConfig.error,
        fullDisable: aConfig.disableItem? false: true
    });
};

core.JSDialog.prototype.sendMessage = function(aMethod, aMessage, aOkHandler, aErrorHandler, aDisableMe){
    core.net.sendMessage({
        dialog: this.id,
        application: this.application,
        method: aMethod,
        message: aMessage,
        disableMe: aDisableMe,
        okHandler: aOkHandler,
        errorHandler: aErrorHandler
    });
}

core.JSFrame = function(){};

core.extendClass('core.JSFrame', 'core.Class');

core.JSFrame.prototype.init = function(config){
    this['core.Class_init'](config);
    var instance = this;
    this.code = config.code;
    this.title = config.title;
    this.instanceID = config.instanceID;
    this.application = config.application;
    this.parentWorkspace = config.workspace;
//    core.log('Creating title: ',this.code, this.title, this.instanceID,
//            this.application, this.parentWorkspace);
    this.closeable = config.closeable;
    this.dynamic = config.dynamic;
    this.frame = new core.ws.Frame({
        code: config.code,
        parentWorkspace: this.parentWorkspace,
        title: this.title,
        icon: config.icon,
        closeable: this.closeable,
        status: config.status,
        dynamic: this.dynamic
    });
    this.frame.body.on('body_change', function(aBody, e, aItem){
        instance.refresh(aItem, false);
    });
    this.frame.jsFrame = this;
    if(config.status)
        this.frame.updateStatus(config.statusLine);
    this.handlers = {};
};

core.JSFrame.prototype.setMessageHandler = function(aMessage, aObject, aMethod){
    this.handlers[aMessage] = {
        object: aObject,
        method: aMethod
    };
};

core.JSFrame.prototype.getMessageHandler = function(aMessage){
    return this.handlers[aMessage];
};

core.JSFrame.prototype.dispose = function(){};

core.JSFrame.prototype.updateStatus = function(aData){
    this.frame.updateStatus(aData.status || '');
};

core.JSFrame.prototype.requestClose = function(aFrameHolder){
    var instance = this;
    this.send({
        method:'requestClose',
        disable: this.frame
    });
}

core.JSFrame.prototype.send = function(aConfig){
    core.net.sendMessage({
        app: this.application.jsAppCode,
        frame: this.instanceID,
        application: this.application,
        method: aConfig.method,
        message: aConfig.message,
        disableMe: aConfig.disable || aConfig.disableItem,
        okHandler: aConfig.ok,
        errorHandler: aConfig.error,
        fullDisable: aConfig.disableItem? false: true
    });
}

core.JSFrame.prototype.sendMessage = function(aMethod, aMessage, aOkHandler, aErrorHandler, aDisableMe){
    core.net.sendMessage({
        app: this.application.jsAppCode,
        frame: this.instanceID,
        application: this.application,
        method: aMethod,
        message: aMessage,
        disableMe: aDisableMe,
        okHandler: aOkHandler,
        errorHandler: aErrorHandler
    });
}

core.JSFrame.prototype.loadContents = function(){};

core.JSFrame.prototype.refresh = function(aElement, aRefresh){
//#ifdef DESKTOP
    if(aRefresh)
        this.frame.body.refresh(aRefresh);
    else
        aElement.refresh();
//#endif
//#ifdef MOBILE
    core.desktop.refreshDesktop();
//#endif
};

core.JSFrame.prototype.setContent = function(aItems, aColumns, aRows, aDefaultControl){
    this.frame.body.setContent(aItems, aColumns, aRows);
    this.frame.body.defaultControl = aDefaultControl;
    this.frame.updateLayout();
}

core.app = {};

core.app.Application = function(){};

core.extendClass('core.app.Application', 'core.JSApplication');

//#ifdef DESKTOP
core.app.Application.prototype.objectToWSItem = function(aObject, aWorkspace){
    if(!aObject)
        return null;
//    core.log('creating element',aObject.type);
    if(aObject.type=='holder'){
        var h = new core.ws.FrameHolder({
            workspace: aWorkspace,
            name: aObject.code,
            frameCodes: aObject.frames,
            locked: aObject.locked
        });
//        core.log('for frame ', aWorkspace.name,
//                'active frame is '+aObject.activeFrame, 'frames:', aObject.frames);
        h.activeFrameCode = aObject.activeFrame
        aWorkspace.registerFrameHolder(h);
        return h;
    }
    if(aObject.type=='splitter'){
        var p = new core.SplittedPanel({
            workspace: aWorkspace,
            name: aObject.code,
            divider: aObject.ratio,
            vertical: aObject.vertical,
            leftElement: this.objectToWSItem(aObject.left, aWorkspace),
            rightElement: this.objectToWSItem(aObject.right, aWorkspace)
        });
        return p;
    }
    return null;
}
//#endif

core.app.Application.prototype.applicationList = function(aObject){
//#ifdef DESKTOP
    this.send({
        method: 'showApplication',
        disable: core.desktop
    });
//#endif
//#ifdef MOBILE
    core.desktop.apps = aObject.apps;
    core.desktop.appListClick();
//#endif

};

core.app.Application.prototype.removeApplication = function(aObject){
//    core.log('removeApplication', aObject);
    if(!aObject || !aObject.application)
        return false;
    core.jsApplications[aObject.application] = null;
};

//#ifdef DESKTOP
core.app.Application.prototype.removeWorkspace = function(aObject){
//    core.log('removeWS: ', aObject.workspace);
    if(!aObject || !aObject.workspace)
        return false;
    for (var i = 0; i < this.desktop.workspaces.length; i++) {
        var ws = this.desktop.workspaces[i];
//        core.log('removeWS: ', aObject.workspace, ws.name);
        if(ws.name==aObject.workspace){
            return this.desktop.removeWorkspace(ws);
        }
    }
    return false;
};

core.app.Application.prototype.showWorkspace = function(aObject){
    if(!aObject || !aObject.workspace)
        return false;
    for (var i = 0; i < this.desktop.workspaces.length; i++) {
        var ws = this.desktop.workspaces[i];
        if(ws.name==aObject.workspace){
            return this.desktop.showWorkspace(ws);
        }
    }
    return false;
};

//#endif
core.app.Application.prototype.removeFrame = function(aObject){
    if(!aObject || !aObject.app || !aObject.frame || !aObject.instance)
        return false;
    var app = core.jsApplications[aObject.app];
    if(!app)
        return false;
    var frame = app.frames[aObject.instance];
    if(!frame)
        return false;
    frame.dispose();
    app.frames[aObject.instance] = null;
//#ifdef DESKTOP
    for (var i = 0; i < this.desktop.workspaces.length; i++) {
        var ws = this.desktop.workspaces[i];
        for(var j = 0; j<ws.frameHolders.length; j++){
            var fh = ws.frameHolders[j];
            fh.removeFrame(frame.frame, true);
        }
    }
//#endif
//#ifdef MOBILE
    core.desktop.body.removeFrame(frame.frame, true);
//#endif
    return true;
};

core.app.Application.prototype.removeDialog = function(aObject){
    if(!aObject || !aObject.dialog){
        core.log('!removeDialog params');
        return false;
    }

    var dlg = core.jsDialogs[aObject.dialog];
    if(!dlg){
        core.log('!removeDialog '+aObject.dialog);
        return false;
    }
    core.log('Removing dialog '+aObject.dialog);
    core.desktop.closeDialog(dlg.dialog);
    core.jsDialogs[aObject.dialog] = null;
};

core.app.Application.prototype.addDialog = function(aObject){
    core.log('addDialog:: ', aObject.app, aObject.dialog, aObject.jsClass);
    if(!aObject || !aObject.app || !aObject.dialog || !aObject.jsClass){
        return false;
    }
    
    var app = core.jsApplications[aObject.app];
    if(!app){
        return false;
    }
    var dlg = core.jsDialogs[aObject.dialog];
    if(dlg){
        return false;
    }
    var constructor = core.findElementByItsName(aObject.jsClass);
    if(constructor){
        var instance = new constructor();
        core.jsDialogs[aObject.dialog] = instance;
        instance.init({
            application: app,
            id: aObject.dialog,
            data: aObject.object || {}
        });
    }
    return true;
};

core.app.Application.prototype.showFrame = function(aObject){
    if(!aObject || !aObject.app || !aObject.instance){
        return false;
    }
    var app = core.jsApplications[aObject.app];
    if(!app){
        return false;
    }
    var frame = app.frames[aObject.instance]
    if(!frame){
        return false;
    }
    var ws = null;
//#ifdef MOBILE
    for(var k = 0; k<core.desktop.body.frames.length; k++){
        var f = core.desktop.body.frames[k];
        if(f.jsFrame==frame){
            core.desktop.body.showFrame(f);
//            f.body.focus();
            return true;
        }
    }
//#endif
//#ifdef DESKTOP
    ws = this.desktop.getWorkspace(aObject.workspace);
    if(!ws){
        return false;
    }
    //First check activeWorkspace
    if(core.desktop.activeWorkspace){
        var ws0 = core.desktop.activeWorkspace;
        for(var j = 0; j<ws0.frameHolders.length; j++){
            var fh = ws0.frameHolders[j];
            for(var k = 0; k<fh.frames.length; k++){
                var f = fh.frames[k];
                if(f.jsFrame==frame){
                    fh.showFrame(f);
//                    f.body.focus();
                    core.setTimeout(f.body, f.body.focus, 20);
                    return true;
                }
            }
        }        
    }
    var ws0 = ws;
    core.desktop.showWorkspace(ws0);
    for(var j = 0; j<ws0.frameHolders.length; j++){
        var fh = ws0.frameHolders[j];
        for(var k = 0; k<fh.frames.length; k++){
            var f = fh.frames[k];
            if(f.jsFrame==frame){
                fh.showFrame(f);
                core.setTimeout(f.body, f.body.focus, 20);
//                f.body.focus();
                return true;
            }
        }
    }
//#endif
};
core.app.Application.prototype.setWorkspaceTitle = function(aObject){
//#ifdef DESKTOP
    for (var i = 0; i < this.desktop.workspaces.length; i++) {
        var ws = this.desktop.workspaces[i];
        if(ws.name==aObject.workspace){
            core.desktop.setWorkspaceTitle(ws, aObject.caption);
        }
    }
//#endif
};

core.app.Application.prototype.setFrameTitle = function(aObject){
    if(!aObject.app || !aObject.instance)
        return false;
    var app = core.jsApplications[aObject.app];
    if(!app)
        return false;
    var frame = app.frames[aObject.instance];
    if(!frame)
        return false;
//#ifdef DESKTOP
    for (var i = 0; i < this.desktop.workspaces.length; i++) {
        var ws = this.desktop.workspaces[i];
        for(var j = 0; j<ws.frameHolders.length; j++){
            var fh = ws.frameHolders[j];
            fh.setFrameTitle(frame.frame, aObject.title, aObject.icon);
        }
    }
//#endif
//#ifdef MOBILE
    core.desktop.body.setFrameTitle(frame.frame, aObject.title, aObject.icon);
//#endif
    return true;
};

core.app.Application.prototype.addNotify = function(aObject){
    if(core && core.desktop)
        core.desktop.addNotify(aObject);
};

core.app.Application.prototype.addFrame = function(aObject){
//    core.log('Creating frame', aObject.app, aObject.frame,
//            aObject.instance, aObject.jsClass, aObject.frame_holder);
//    for(var id in core.jsApplications){
//        core.log('started app: '+id, aObject.app);
//    }
    if(!aObject || !aObject.app || !aObject.frame || !aObject.instance || !aObject.jsClass){
        return false;
    }
    var app = core.jsApplications[aObject.app];
    if(!app){
        core.log('!app', aObject.app);
        return false;
    }
    if(app.frames[aObject.instance]){
        core.log('!already frame');
        return false;
    }
    var ws = null;
//#ifdef DESKTOP
    ws = this.desktop.getWorkspace(aObject.workspace);
    if(!ws){
        core.log('!ws');
        return false;
    }
//#endif
    var constructor = core.findElementByItsName(aObject.jsClass);
    if(constructor){
        var instance = new constructor();
        app.frames[aObject.instance] = instance;
        instance.init({
            code: aObject.frame,
            title: aObject.title,
            instanceID: aObject.instance,
            application: app,
            icon: aObject.icon,
            workspace: ws,
            status: aObject.status || false,
            statusLine: aObject.statusLine || ' ',
            closeable: aObject.closeable,
            dynamic: aObject.dynamic
        });
        var id = aObject.dynamic?aObject.instance:aObject.frame;
        instance.parentWorkspaceCode = aObject.workspace;
//#ifdef DESKTOP

//        core.log('created');
        //Check all workspaces and add frame

        for (var i = 0; i < this.desktop.workspaces.length; i++) {
            var ws0 = this.desktop.workspaces[i];
            var frameAdded = false;
            for(var j = 0; j<ws0.frameHolders.length; j++){
                var fh = ws0.frameHolders[j];
//                core.log('ws:', ws0.name, 'fh:', fh.name,
//                        'codes:', fh.frameCodes,'frame:', instance.code);
                for(var k = 0; k<fh.frameCodes.length; k++){
                    if(fh.frameCodes[k]==id){
                        fh.addFrame(instance.frame);
                        frameAdded = true;
//                        core.log('Added ws to frameholder:', fh.name, fh.activeFrameCode, aObject.frame);
                        if(fh.activeFrameCode==id){
//                            core.log('Show frame.. '+instance.code);
                            fh.showFrame(instance.frame);
                        }
                    }
                }
            }
            if(!frameAdded && aObject.frame_holder){
                for(var j = 0; j<ws0.frameHolders.length; j++){
                    var fh = ws0.frameHolders[j];
    //                core.log('ws:', ws0.name, 'fh:', fh.name,
    //                        'codes:', fh.frameCodes,'frame:', instance.code);
                    if(aObject.frame_holder==fh.name && aObject.frame_workspace==ws0.name){
                        fh.addFrame(instance.frame);
//                        fh.showFrame(instance.frame);
                        break;
                    }
                }

            }
        }
//#endif
//#ifdef MOBILE
        core.desktop.body.addFrame(instance.frame);
//#endif
        instance.loadContents(aObject.data || {});
        instance.frame.refresh(true);
//        fh.refresh(true);
    }
    return true;
};
core.app.Application.prototype.finishLoading = function(aObject){
    core.desktop.unMarkLoading();
}
//#ifdef DESKTOP
core.app.Application.prototype.resetWorkspace = function(aObject){
    for (var i = 0; i < core.desktop.workspaces.length; i++) {
        var ws = core.desktop.workspaces[i];
        if(ws.name==aObject.code){
//            aObject.position = i;
            ws.frameHolders = [];
            this.addWorkspace(aObject, ws);
        }
    }
}

core.app.Application.prototype.addWorkspace = function(aObject, aWorkspace){
//    core.log('Adding workspace: '+aObject.code, aWorkspace);
    var ws = null;
    var is_float = false
    if(aObject.type==1){//Float type
        is_float = true;
    }
    if(!aWorkspace){
        ws = new core.ws.Workspace({
           name: aObject.code,
           caption: aObject.caption,
           closeable: aObject.closeable
        });
        if(aObject.app){
            var app = core.jsApplications[aObject.app];
            if(app){
                app.workspaces[aObject.code] = ws;
                ws.application = app;
            }
            if(is_float){

                ws.floating = true;
                ws.width = aObject.width || 300;
                ws.height = aObject.height || 300;
                ws.collapsed = aObject.collapsed || false;
                ws.vertical = aObject.direction==0 || false;

            }
        }
    }else{
        ws = aWorkspace;
    }
    ws.setRoot(this.objectToWSItem(aObject.item, ws));
    ws.root.hide();
    for(var j = 0; j<ws.frameHolders.length; j++){
        var fh = ws.frameHolders[j];
        for (var id in core.jsApplications) {
            var app = core.jsApplications[id];
            if(!app)
                continue;
            for (var idfr in app.frames) {
                var fr = app.frames[idfr];
                if(!fr)
                    continue;
                var frid = fr.dynamic?fr.instanceID:fr.code;
                for(var k = 0; k<fh.frameCodes.length; k++){
                    if(fh.frameCodes[k]==frid){
                        fh.addFrame(fr.frame);
                        if(fh.activeFrameCode==frid){
                            fh.showFrame(fr.frame);
                        }
                    }
                }
            }
        }
    }
    this.desktop.addWorkspace(ws);
//    core.log('ws selected: ', aObject.selected, this.desktop.workspaces.length);
    if(aObject.selected || aWorkspace)
        this.desktop.showWorkspace(ws);
    ws.root.updateLayout();
    this.desktop.refresh();
}
//#endif

core.app.Application.prototype.init = function(config){
    this.superCall('init', arguments, config);
    this.desktop = core.desktop;
    this.desktop.app = this;
};

core.app.Frame1 = function(){};

core.extendClass('core.app.Frame1', 'core.JSFrame');

core.app.Frame1.prototype.loadContents = function(){
    var instance = this;

    this.button = new core.form.Button({
        text: 'Open addressbook',
        minWidth: 150,
        handler: function(){
            instance.frame.markLoading();
            instance.sendMessage('buttonClick', {}, function(){
                instance.frame.unMarkLoading();
            }, function(){
                instance.frame.unMarkLoading();
            });
        }
    });
    this.openSession = new core.form.Button({
       text: 'Sessions list',
       minWidth: 150,
       handler: function(){
           instance.sendMessage('sessionList', {}, null, null, instance.openSession);
       }
    });

//    this.button2 = new core.form.Button({
//        text: 'Close frame',
//        eventHandlers:[
//            {
//                event: 'press',
//                handler: function(){
//                    instance.button2.markLoading();
//                    instance.application.sendMessage('button2Click', {}, function(){
//                        instance.button2.unMarkLoading();
//                    }, function(){
//                        instance.button2.unMarkLoading();
//                    });
//                }
//            }
//        ]
//    });
    this.frame.body.setContent([this.button, this.openSession], 'd', 'd, d');
    this.frame.updateLayout();
//    this.frame.refresh(true);
}

core.app.Frame2 = function(){};

core.extendClass('core.app.Frame2', 'core.JSFrame');

core.app.Frame2.prototype.loadContents = function(){
    this.html = new core.HTMLPanel({
        html: '<ul><li>Welcome! Now you can:</li>'+
            '<li>Resize frame</li>'+
            '<li>Change frame position by drag\'n\'drop. Use frame title on top of frame</li>'+
            '<li>Copy frames by drag\'n\'drop between workspaces. To do this hover frame title on workspace title on bottom of screen and wait 1 sec</li>'+
            '<li>Start sample AddressBook application</li>'+
            '<li>Edit, create, delete addressbook entries</li>'+
            '<li>Start SessionInfo application</li>'+
            '<li>Send message to any user</li>'+
            '<li>Close any application by pressing [x] on workspace title</li>'+
            '<li>Reload page at any time. Just for testing purposes. All running applications should restore it\'s state</li></ul>'
    });

//    this.grid = new core.grid.GridPanel({
//        headerCaptions: ['Row#01', 'Row 02', 'Row#03'],
//        columns: '0.2, 0.7, 0.3'
//    });
    
    this.setContent([this.html], '1', '1');
//    for (var i = 0; i < 50; i++) {
//        this.grid.addRow(0, ['Hi korea! '+i, '<div style="text-align: center; width: 100%; padding: 5px;">Another content '+i+'</div>']);
//    }
};

core.ui.createButtons = function(config){
    var buttons = $.makeArray(config.buttons);
    var btns = [];
    var cols = '';
    var align = config.align || 'right';
    for (var i = 0; i < buttons.length; i++) {
        var c = 'd';
        var al = 'left';
        if(i==0){
            al = 'right'
            if(align!='left')
                c = '1';
        }else{
            if(i==buttons.length-1){
                if(align!='right')
                    c = '1';
            }
        }
        if(i>0)
            cols += ',';
        cols += c;
        var btn = new core.form.Button({
            text: buttons[i],
            align: al,
            handler: function(button){
                config.handler(button.buttonIndex);
            }
        });
        btn.buttonIndex = i;
        btns.push(btn);
    }
    core.log('Creating buttons: ', cols, btns.length);
    return new core.Box({
        items: btns,
        columns: cols,
        rows: 'd',
        colspan: config.colspan || 1
    });
};

core.QuestionDialog = function(){};
core.extendClass('core.QuestionDialog', 'core.JSDialog');
core.QuestionDialog.prototype.createDialog = function(aData){
    var instance = this;
    var btns = core.ui.createButtons({
        buttons: aData.buttons,
        align: 'center',
        handler: function(index){
            instance.send({
                method: 'buttonClick',
                message: {
                    button: index
                },
                disable: dlg
            });
        }
    });
    var dlg = new core.Dialog({
        title: 'Message:',
        maxWidth: 350,
        items: [
            new core.Label({
                text: aData.question,
                align: 'left'
            }), btns
        ], 
        columns: '1',
        rows: 'd, d',
        defaultItem: btns.items[aData.defaultButton]
    });
    return dlg;
};
